/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.AddGroup;
import com.comac.ins.common.core.validate.EditGroup;
import com.comac.ins.common.excel.utils.ExcelUtil;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdAlgorithmConfigBo;
import com.comac.ins.isfd.domain.bo.query.IsfdAlgorithmConfigQueryBo;
import com.comac.ins.isfd.domain.vo.IsfdAlgorithmConfigVo;
import com.comac.ins.isfd.service.IIsfdAlgorithmConfigService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 算法配置存储
 *
 * @author hxloongs
 * @date 2025-05-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/algorithmConfig")
public class IsfdAlgorithmConfigController extends BaseController {

    @Autowired
    private IIsfdAlgorithmConfigService isfdAlgorithmConfigService;

    /**
     * 查询算法配置存储列表
     */
    @SaCheckPermission("isfd:algorithmConfig:list")
    @PostMapping("/list")
    public TableDataInfo<IsfdAlgorithmConfigVo> list(@RequestBody IsfdAlgorithmConfigQueryBo queryBo) {
        return isfdAlgorithmConfigService.queryPageList(queryBo);
    }

    /**
     * 导出算法配置存储列表
     */
    @SaCheckPermission("isfd:algorithmConfig:export")
    @Log(title = "算法配置存储", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IsfdAlgorithmConfigBo bo, HttpServletResponse response) {
        List<IsfdAlgorithmConfigVo> list = isfdAlgorithmConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "算法配置存储", IsfdAlgorithmConfigVo.class, response);
    }

    /**
     * 获取算法配置存储详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("isfd:algorithmConfig:query")
    @GetMapping("/{id}")
    public R<IsfdAlgorithmConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                            @PathVariable Long id) {
        return R.ok(isfdAlgorithmConfigService.queryById(id));
    }

    /**
     * 新增算法配置存储
     */
    @SaCheckPermission("isfd:algorithmConfig:add")
    @Log(title = "算法配置存储", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IsfdAlgorithmConfigBo bo) {
        return toAjax(isfdAlgorithmConfigService.insertByBo(bo));
    }

    /**
     * 修改算法配置存储
     */
    @SaCheckPermission("isfd:algorithmConfig:edit")
    @Log(title = "算法配置存储", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IsfdAlgorithmConfigBo bo) {
        return toAjax(isfdAlgorithmConfigService.updateByBo(bo));
    }

    /**
     * 删除算法配置存储
     *
     * @param ids 主键串
     */
    @SaCheckPermission("isfd:algorithmConfig:remove")
    @Log(title = "算法配置存储", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(isfdAlgorithmConfigService.deleteWithValidByIds(List.of(ids), true));
    }
}
